<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css"/>
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			#search{
				width: 66%;
				margin: auto auto;
			}
			/*#header{
				background-color: #FCEEAF;
				color: antiquewhite;
			}*/
			#navigation{
				background-color: rgb(255,209,0);
				color: black;
			}
			.show {
				display: block;
			}
			.hide{
				display: none;
			}
			#navigation div> button{
				border:  none;
				color: black;
			}
			
			.searchbtn{width:60px;height:40px;padding: 0 0;margin: 2px -6px 0 0;border-radius: 20px 0 0 20px;background:rgba(0,0,0,0.5) url(images/search_11.png) no-repeat;background-size: 40% 60%;background-origin:content-box;background-position: 18px 8px;}
			input[type=text] {width: 70%;margin-bottom: 0;border-radius:0 20px 20px 0;background: rgba(0,0,0,0.5);}
		</style>
	</head>

	<body>
		<header id="navigation" class="mui-bar mui-bar-nav">
			<div id="nav_head1" class="show">
				<span class="mui-icon FontAwesome icon-qrcode mui-pull-left"></span>
				<div class="mui-title" style="height: 100%;">
					<button type="button" class="searchbtn"></button>
					<input type="text" class="mui-input-clear" placeholder="" />					
				</div>
				<span class="mui-icon mui-icon-chat mui-pull-right"></span>
			</div>
			
			<div id="nav_head2" class="hide">
				<button class="mui-icon FontAwesome icon-phone mui-pull-left" style="background-color: transparent; border: none;"></button>
				<span class="mui-title">
					购物车
				</span>
				<button class="mui-icon FontAwesome icon-circle-blank mui-pull-right" style="color:black; background-color: transparent; border: none;"></button>
			</div>
			
			<div id="nav_head3" class="hide">
				<span class="mui-title">
					个人中心
				</span>
				<button class="mui-icon FontAwesome icon-envelope mui-pull-right" style="background-color: transparent; border: none;"></button>
			</div>
		</header>
		
		<nav id="tabcard" class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item mui-active" href="tab-webview-subpage-main.html">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-category.html">
				<span class="mui-icon mui-icon-list"></span>
				<span class="mui-tab-label">分类</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-active.html">
				<span class="mui-icon mui-icon-image"></span>
				<span class="mui-tab-label">活动</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-cart.html">
				<span class="mui-icon mui-icon-trash"></span>
				<span class="mui-tab-label">购物车</span>
			</a>
			<a class="mui-tab-item" href="tab-webview-subpage-personal.html">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">个人中心</span>
			</a>
		</nav>
		<script src="js/mui.min.js"></script>
		<script src="js/common.js" type="text/javascript">
		</script>
		<script type="text/javascript" charset="utf-8"> 
			 //mui初始化
			mui.init({
				statusBarBackground:'#D385EF'
			});
//			alert(subpages[0]);
			var subpages = ['tab-webview-subpage-main.html', 'tab-webview-subpage-category.html', 'tab-webview-subpage-active.html', 'tab-webview-subpage-cart.html','tab-webview-subpage-personal.html'];
			var subpage_style = {
				top: '44px',
				bottom: '51px'
			};
			var aniShow = {};
			
			var scanCode_style = {
				top:'0px',
				bottom:'0px'
			};
			
			
			
			
			 //创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
				ws = plus.webview.currentWebview();
				wo = ws.opener();
				
				plus.webview.show(ws,'zoom-fade-out');
				plus.nativeUI.closeWaiting();
				
				//调用原生扫码接口
				var scanCode = document.getElementsByClassName('icon-qrcode')[0];
				//监听单击事件
				scanCode.addEventListener('tap',function(){
					//创建并打开扫描窗口
					var scanView = clicked('scanCode.html',true,true,scanCode_style);
				});
				
				
				
				var self = plus.webview.currentWebview();
				for (var i = 0; i < 5; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					if (i > 0) {
						sub.hide();
					}else{
						temp[subpages[i]] = "true";
						mui.extend(aniShow,temp);
					}
					self.append(sub);
				}
			});
				//alert(plus.webview.all().length);
			
				 //当前激活选项
				activeTab = subpages[0];
				 //选项卡点击事件
				var switchTab = false;
				mui('.mui-bar-tab').on('tap', 'a', function(e) {
					var targetTab = this.getAttribute('href');
					if (targetTab == activeTab) {
						return;
					}
					
					
					//获取当前点击选项
			var tname = this.querySelector('.mui-tab-label').innerHTML;
					if(switchTab && (tname == '首页'||tname == '分类'||tname == '活动')){
						document.getElementById('nav_head1').setAttribute('class','show');
						document.getElementById('nav_head2').setAttribute('class','hide');
						document.getElementById('nav_head3').setAttribute('class','hide');
						switchTab = false;
					}else if(tname == '购物车'){/*alert(tname);*/
						document.getElementById('nav_head1').setAttribute('class','hide');
						document.getElementById('nav_head2').setAttribute('class','show');
						document.getElementById('nav_head3').setAttribute('class','hide');
						switchTab = true;
					}else if(tname == '个人中心'){
						document.getElementById('nav_head1').setAttribute('class','hide');
						document.getElementById('nav_head2').setAttribute('class','hide');
						document.getElementById('nav_head3').setAttribute('class','show');
						switchTab = true;
			};	
					
					
					
				//显示目标选项卡
				//若为iOS平台或非首次显示，则直接显示
					if(mui.os.ios||aniShow[targetTab]){
						plus.webview.show(targetTab);
					}else{
					//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow,temp);
						plus.webview.show(targetTab,"fade-in",300);
					}
				//隐藏当前;
					plus.webview.hide(activeTab);
				//更改当前活跃的选项卡
					activeTab = targetTab;
				});
			
			
			
			
			
			
			 //自定义事件，模拟点击“首页选项卡”
			document.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if (defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});
		</script>
	</body>

</html>